import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";

// https://vite.dev/config/
export default defineConfig(({ mode }) => {
  const config = loadEnv(mode, "./");
  return {
    plugins: [vue()],
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "./src"),
        "*": path.resolve(""),
      },
    },
    server: {
      hmr: true,
      proxy: {
        "/api": {
          target: config.VITE_BASE_URL, //目标url
          changeOrigin: true, //支持跨域
          rewrite: (path) => path.replace(/^\/api/, ""),
          //重写路径,替换/api
        },
      },
    },
  };
});
